<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="../include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
String id = request.getParameter("id");
%>
<html>
  <head>
    <title>资源发现</title>
     <%@ include file="../include/common.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/ui/jquery.ui.progressbar.js"></script>
	<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/jqueryui/jquery-ui.css" />
	<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/jqueryui/demos.css" />
	<style rel="stylesheet"  type="text/css">
		.ui-progressbar .ui-progressbar-value {background-image: url(${pageContext.request.contextPath}/style/default/images/pbar-ani.gif); }
	</style>
     <script type=text/javascript>
     	var id = '<%=id%>';
     	 function closewin(){
	   		getTopWin(window).closejBox("show-find-progress");
  		}
  		function refreshTable()
  		{
  			   var win = getTopWin(window).currentWin["show-find-progress"];
  			   win.refreshTable();
  		}
    	function checkSucess()
		{	
			$.ajax({
				type:'post',
				url:'/bsm/resource/res-find!checkSucces.action?id='+id,
				global:false,
				async:false,
				cache:false,
				dataType:'json',
				success:function(data,textStatus){
						showMsg(data.infos,false);
						if(data.finished){
							$( "#progressbar").progressbar( "option", "value",100);
							$( "#loadedDiv").html("已完成本次资源发现过程，页面将在3秒内自动【关闭】。");
							 refreshTable();
							 setTimeout("closewin()",3000);
						}else{
							setTimeout("checkSucess()",2000);
						}
					}
				});
		}
		function showMsg(infos,isFirst){
			var loaded = 0;
			for(var i=0; i<infos.length; i++){
				var info = infos[i];
				if(info.status>-1){
					loaded++;
				}
				
				if(isFirst){
						$("#promsg").append("<li> <span id='stat_"+info.id+"' class='stat_loading'>&nbsp;</span> <span class='infoMsg'>"+info.msg+"</span> </li>");
				}
				
				if(info.status==0){
					$("#stat_"+info.id).attr("class","stat_loading");
				}else if(info.status==1){
					$("#stat_"+info.id).attr("class","stat_complete");
				}else{
					$("#stat_"+info.id).attr("class","stat_unfinished");
				}
			
			}
			if(isFirst){
				$("#progressbar").progressbar({
					value: Math.ceil(loaded*100/infos.length)
				});
			}else{
				$("#progressbar" ).progressbar( "option", "value", Math.ceil(loaded*100/infos.length) );
			}
			$("#loadedDiv").html("正在处理第 "+loaded+" / "+infos.length+"项");
		}
		$(document).ready(function(){
 		$.ajax({
				type:'post',
				url:'/bsm/resource/res-find!doFind.action?id='+id,
				global:false,
				async:true,
				cache:false,
				dataType:'json',
				success:function(data,textStatus){
						if(!data.dofind){
							$("#errormsg").html("资源正在发现中！");
						}
						var infos = data.infos;
						showMsg(infos,true);
					
						setTimeout("checkSucess()",2000);
					
				}
			});
		});
     </script>
  </head>
<body>
  <div id="errormsg"></div>
	<div class="demo">
	<div id="progressbar"></div>
	<div id="loadedDiv"></div>
</div>
<div class="promsg" >
<ul id="promsg"></ul>
 
</div>

</body>
</html>
